
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mytools;

import com.opensymphony.xwork2.ActionSupport;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;

/**

 *

 * @author xiaoxiao

 */
public class examoperation extends ActionSupport {
    private int userid;
    private int eid;
    private examDAO ed;
    private exam examadd;
    private exam exam;
    private String creattime;
    private String name;
    private String descript;
    private List<choice> danxuan;
    private List<choice> duoxuan;
    private List<judge> judge;
    private List<question> question;

    public examoperation() {
    }

    public String examscan() throws Exception {
        setExam(new exam());
        setEd(new examDAO());
        setExam(getEd().getexam(getEid()));
        String c = getExam().getEc();
        String j = getExam().getEj();
        String q = getExam().getEq();
        String ec;
        String ej;
        String eq;
        if (c != null && !c.equals("")) {
            ec = c.substring(0, c.length() - 1);
        } else {
            ec = "0";
        }

        if (j != null && !j.equals("")) {
            ej = j.substring(0, j.length() - 1);
        } else {
            ej = "0";
        }

        if (q != null && !q.equals("")) {
            eq = q.substring(0, q.length() - 1);
        } else {
            eq = "0";
        }

        setDanxuan(getEd().getdanxuan(ec));
        setDuoxuan(getEd().getduoxuan(ec));
        setJudge(getEd().getjudge(ej));
        setQuestion(getEd().getquestion(eq));
        return SUCCESS;

    }

    public String examedit() throws Exception {
        exam exam = new exam();
        exam.setEid(getEid());
        exam.setCreattime(getCreattime());
        exam.setDescript(getDescript());
        exam.setName(getName());
        examDAO ed = new examDAO();
        int i = ed.editexam(exam);
        if (i > 0) {
            return SUCCESS;
        } else {
            return INPUT;
        }

    }

    public String addexam() throws Exception {
        setEd(new examDAO());
        getExamadd().setCreattime(new Date().toLocaleString());
        int i = getEd().addexam(getExamadd());
        if (i == 1) {
            return SUCCESS;
        } else {
            return ERROR;
        }
    }

    public String updateej() throws Exception {
        HttpServletRequest request = ServletActionContext.getRequest();
        String id[] = request.getParameterValues("id");
        String result = "";
        String seprater = ",";
        if (id != null) {
            for (int i = 0; i < id.length; i++) {
                result += id[i] + seprater;
            }
        }
        setEd(new examDAO());
        getEd().updateej(result, getEid());
        return SUCCESS;
    }

    public String updateeq() throws Exception {
        HttpServletRequest request = ServletActionContext.getRequest();
        String id[] = request.getParameterValues("id");
        String result = "";
        String seprater = ",";
        if (id != null) {
            for (int i = 0; i < id.length; i++) {
                result += id[i] + seprater;
            }
        }
        setEd(new examDAO());
        getEd().updateeq(result, getEid());
        return SUCCESS;
    }

    public String updateec() throws Exception {
        HttpServletRequest request = ServletActionContext.getRequest();
        String id[] = request.getParameterValues("id");
        String result = "";
        String seprater = ",";
        if (id != null) {
            for (int i = 0; i < id.length; i++) {
                result += id[i] + seprater;
            }
        }
        setEd(new examDAO());
        getEd().updateec(result, getEid());
        return SUCCESS;
    }

    public String deleteexam() throws Exception {
        setEd(new examDAO());
        int i = getEd().deleteexam(getEid());
        if (i == 1) {
            return SUCCESS;
        } else {
            return ERROR;
        }
    }

    public String viewexam() throws Exception {
        setEd(new examDAO());
        setExam(getEd().getexam(getEid()));
        return SUCCESS;
    }

    public String execute() throws Exception {

        throw new UnsupportedOperationException("Not supported yet.");

    }

    /**
     * @return the eid
     */
    public int getEid() {
        return eid;
    }

    /**
     * @param eid the eid to set
     */
    public void setEid(int eid) {
        this.eid = eid;
    }

    /**
     * @return the ed
     */
    public examDAO getEd() {
        return ed;
    }

    /**
     * @param ed the ed to set
     */
    public void setEd(examDAO ed) {
        this.ed = ed;
    }

    /**
     * @return the examadd
     */
    public exam getExamadd() {
        return examadd;
    }

    /**
     * @param examadd the examadd to set
     */
    public void setExamadd(exam examadd) {
        this.examadd = examadd;
    }

    /**
     * @return the exam
     */
    public exam getExam() {
        return exam;
    }

    /**
     * @param exam the exam to set
     */
    public void setExam(exam exam) {
        this.exam = exam;
    }

    /**
     * @return the creattime
     */
    public String getCreattime() {
        return creattime;
    }

    /**
     * @param creattime the creattime to set
     */
    public void setCreattime(String creattime) {
        this.creattime = creattime;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return the descript
     */
    public String getDescript() {
        return descript;
    }

    /**
     * @param descript the descript to set
     */
    public void setDescript(String descript) {
        this.descript = descript;
    }

    /**
     * @return the danxuan
     */
    public List<choice> getDanxuan() {
        return danxuan;
    }

    /**
     * @param danxuan the danxuan to set
     */
    public void setDanxuan(List<choice> danxuan) {
        this.danxuan = danxuan;
    }

    /**
     * @return the duoxuan
     */
    public List<choice> getDuoxuan() {
        return duoxuan;
    }

    /**
     * @param duoxuan the duoxuan to set
     */
    public void setDuoxuan(List<choice> duoxuan) {
        this.duoxuan = duoxuan;
    }

    /**
     * @return the judge
     */
    public List<judge> getJudge() {
        return judge;
    }

    /**
     * @param judge the judge to set
     */
    public void setJudge(List<judge> judge) {
        this.judge = judge;
    }

    /**
     * @return the question
     */
    public List<question> getQuestion() {
        return question;
    }

    /**
     * @param question the question to set
     */
    public void setQuestion(List<question> question) {
        this.question = question;
    }

    /**
     * @return the userid
     */
    public int getUserid() {
        return userid;
    }

    /**
     * @param userid the userid to set
     */
    public void setUserid(int userid) {
        this.userid = userid;
    }
}
